package com.example.Jd_javaWeb_maven0402.controller;

import com.example.Jd_javaWeb_maven0402.bean.UserInfoBean;
import com.example.Jd_javaWeb_maven0402.model.UserModel;
import com.example.Jd_javaWeb_maven0402.uilts.MyUilts;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "UserInfoAddServlet", value = "/UserInfoAddServlet")
public class UserInfoAddServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    //设置编码
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        //获取表单数据并把表单数据保存在实例中
        UserInfoBean userInfoBean = MyUilts.getNewInstance(UserInfoBean.class);
        userInfoBean.setUserName(request.getParameter("userName"));
        userInfoBean.setUserPsw(request.getParameter("userPsw"));
        userInfoBean.setPhone(request.getParameter("phone"));
        //userInfoBean.setUserDate(request.getParameter("userDate"));
        //调用model层进行数据保存的业务逻辑处理

        int i = MyUilts.getNewInstance(UserModel.class).addUserInfo(userInfoBean);
        //数据保存成功之后，跳转的保存结果界面
        request.setAttribute("intAdd", i);
    }
}
